function twoSum(nums, target) {
  // 遍历数组从第一个到倒数第二个
  for (let i = 0; i < nums.length - 1; i++) {
    // 遍历数组从第二个到最后一个
    for (let j = i + 1; j < nums.length; j++) {
      if (nums[i] + nums[j] === target) {
        return [i, j];
      }
    }
  }
}

const nums = [2, 7, 11, 15];
const target = 9;
console.log(twoSum(nums, target));

const nums2 = [3, 2, 4];
const target2 = 6;
console.log(twoSum(nums2, target2));
